Change CAN speed
The Hasselt code uses a non-standard bus speed of 250kbps. In order to stay in sync with the rest of the VSCP development community, I changed it back to the 125kbps which everyone else is using.
Changing the bus speed is easy. The file can16F66K80.c includes a function vscp18f_init() which sets the registers that in turn set the CAN bus speed. Both 250kbps and 125kbps settings are already in this function, so we’ll comment out the 250kbps settings and uncomment the 125kbps settings.
////////////////////////////////////////////////////////////////////////////////
// vscp18f_init
//
void vscp18f_init( BOOL bExtended )
{
// Set CAN module into configuration mode
vscp18f_cansetmode( CAN18F_MODE_CONFIG );
// 32MHZ clock, 125kbps
// T1=12, T2=4, BTQ=16, Sample point=75,SWJ=1,bitrate=125,error=0%
BRGCON1 = 0x07;
BRGCON2 = 0xB8;
BRGCON3 = 0x05;
// 32MHZ clock, 250kbps
// T1=12, T2=4, BTQ=16, Sample point=75,SWJ=1,bitrate=250,error=0%
// Calculator: http://www.kvaser.com/en/support/bit-timing-calculator.html
//BRGCON1 = 0x03;
//BRGCON2 = 0xAC;
//BRGCON3 = 0x03;
// Receive only valid extended messages
// Receive buffer 0 overflow will write to buffer 1
if ( bExtended ) {
RXB0CON = 0x44; // all = 0x64, extended = 0x44
...
Obviously we’ll need to set the can0 interface for the daemon to 125kbps as well. On Linux this is how:
ip link set can0 down
ip link set can0 up type can bitrate 125000 sample-point 0.875
Done!